<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
</head>

<body>
    <div id="root">
        <h2>学校名称：{{school.name}}</h2>
        <h2>学校地址：{{school.address}}</h2>
        <h2>学校校长：{{school.leader}}</h2>
        <hr>
        <button @click="addSex">添加性别</button>
        <h2>姓名：{{student.name}}</h2>
        <h2 v-if="student.sex">性别：{{student.sex}}</h2>
        <h2>年龄：真实{{student.age.realAge}},对外{{student.age.speakAge}}</h2>
        <h2>对象们</h2>
        <ul>
            <li v-for="(item, index) in student.friends" :key="index">
                {{item.name}}-{{item.age}}
            </li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false //取消生产提示

        const vm = new Vue({
            el: '#root',
            data() {
                return {
                    school: {
                        name: '尚硅谷',
                        address: '北京昌平',
                    },
                    student: {
                        name: '李文泰',
                        age: {
                            realAge: 20,
                            speakAge: 18
                        },
                        friends: [{
                            name: '迪丽热巴',
                            age: 20
                        }, {
                            name: '江疏影',
                            age: 20
                        }]
                    }
                }
            },
            methods: {
                addSex() {
                    // Vue.set(this.student, 'sex', '男')
                    this.$set(this.student, 'sex', '男')
                }
            },
        })
    </script>
</body>

</html>